//package com.lill.support.aspect;
//
//import java.lang.reflect.Method;
//import java.net.InetAddress;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.Signature;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//import org.springframework.web.multipart.MultipartFile;
//
//import com.lill.support.annotation.RepeatSelect;
//
//@Component
//@Aspect
//public class NoRepeatSubmitAopAspect {
//	
//	protected static Logger logger = LoggerFactory.getLogger(NoRepeatSubmitAopAspect.class);
//	
//	@Resource(name="commonRedisTemplate")
//    private RedisTemplate<String, Integer> redisTemplate;
// 
//    @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
//    public Object arround(ProceedingJoinPoint pjp) {
//        try {
//        	boolean result=false;
//        	for (Object object : pjp.getArgs()) {
//        		if (object instanceof MultipartFile || object instanceof MultipartFile[]) {
//        			result=true;break;
//    			}
//        	}
//        	if(result){
//        		return pjp.proceed();
//        	}
//        	
//        	
//        	ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        	HttpServletRequest request = attributes.getRequest();
//        	String uri=request.getRequestURI();
//        	
//        	if(uri.endsWith(".html")){
//        		return pjp.proceed();
//        	}
//        	
//        	Signature signature = pjp.getSignature();
//        	MethodSignature methodSignature = (MethodSignature)signature;
//        	Method targetMethod = methodSignature.getMethod();
//        	Method realMethod = pjp.getTarget().getClass().getDeclaredMethod(signature.getName(), targetMethod.getParameterTypes());
//                
//            if(realMethod.isAnnotationPresent(RepeatSelect.class)){
//            	return pjp.proceed();
//            }
//            
//            String ipAddress = request.getHeader("x-forwarded-for");
//            if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
//                ipAddress = request.getHeader("Proxy-Client-IP");
//            }
//            if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
//                ipAddress = request.getHeader("WL-Proxy-Client-IP");
//            }
//            if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
//                ipAddress = request.getRemoteAddr();
//                if (ipAddress.equals("127.0.0.1")) {
//                    // 根据网卡取本机配置的IP
//                    InetAddress inet = InetAddress.getLocalHost();
//                    ipAddress = inet.getHostAddress();
//                }
//            }
//            
//            logger.info("--------ipAddress:"+ipAddress);
//            // 对于通过多个代理的情况，第一个IP为客户端真实IP,多个IP按照','分割
//            if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length()  // = 15
//                if (ipAddress.indexOf(",") > 0) {
//                    ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
//                }
//            }
//            
//            String key="NoRepeatSubmit:"+ipAddress+uri;
//            logger.info("--------key:"+key);
//            
//            return pjp.proceed();
////            ValueOperations<String, Integer> opsForValue = redisTemplate.opsForValue();
////            if (opsForValue.get(key) == null) {// 如果缓存中有这个url视为重复提交
////            	opsForValue.set(key, 0, 5, TimeUnit.SECONDS);
////            }
////        	
////            return null;
//        } catch (Throwable e) {
//        	logger.error(e.getMessage(), e);
//        	return null;
//        }
//    }
//
//}
